﻿
-----------------------------------------------------------------------
-- MatrixError.lua
--
-- A Framework for World Of Warcraft addons
-- Copyright (C) 2007  wwkkii
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-- 
-- Home Page: http://code.google.com/p/wowmatrix
-----------------------------------------------------------------------

local __version__ = { "MatrixError", 0, 1, 1 };
if (MatrixUpdateVersion(__version__)) then return; end

-----------------------------------------------------------------------
-- variabiels
-----------------------------------------------------------------------

local exception_mode = 0;

-----------------------------------------------------------------------
-- matrix Functions
-----------------------------------------------------------------------

matrix.StopOnCrash = function()
	exception_mode = 0;
end

matrix.StopOnError = function()
	exception_mode = 1;
end

matrix.StopOnWarning = function()
	exception_mode = 2;
end

matrix.IsErrorStop = function()
	return (exception_mode >= 1);
end

matrix.IsWarningStop = function()
	return (exception_mode >= 2);
end

matrix.Crash = function(mesg, ...)
	mesg = "Crash: "..matrix.TextInfo(mesg, ...);
	matrix.Cout(1, 0, 1, mesg);
	matrix.Throw(mesg, nil, 3);
end

matrix.Error = function(mesg, ...)
	mesg = "Error: "..matrix.TextInfo(mesg, ...);
	matrix.Cout(1, 0, 0, mesg);
	if (exception_mode >= 1) then
		matrix.Throw(mesg, nil, 3);
	end
end

matrix.Warning = function(mesg, ...)
	mesg = "Warning: "..matrix.TextInfo(mesg, ...);
	matrix.Cout(0, 1, 1, ...);
	if (exception_mode >= 2) then
		matrix.Throw(mesg, nil, 3);
	end
end
